package com.chixing.controller;

import com.chixing.pojo.Review;
import com.chixing.service.ReviewService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class ReviewController {
    @Autowired
    private ReviewService reviewService;

    // 根据主键查询评价
    @GetMapping(value = {"review/{carId}/page/{pageNum}","review/{carId}/page"})
    @ResponseBody
    public ServerResponse getReviewByCarId(@PathVariable("carId") Integer carId,
                                           @PathVariable(value = "pageNum",required = false) Integer pageNum){
        if (pageNum == null)
            pageNum = 1;
        return reviewService.getReviewByCarId(carId,pageNum);
    }

    @PutMapping("review/{reviewId}/{custId}/{status}")
    @ResponseBody
    public ServerResponse updateReviewByCarId(@PathVariable ("reviewId")Integer reviewId,
                                                @PathVariable("custId") Integer custId,
                                                @PathVariable("status") Integer status){
        return reviewService.updateReviewByCarId(reviewId,custId,status);
    }
}